import { useEffect, useState } from 'react'
import LineGraph from './components/LineGraph/index'
import styles from './index.module.less'
const GuessAsking = (props) => {
	const [eleStyle, setEleStyle] = useState({ width: 0, height: 0 })
	useEffect(() => {
		const element = document.getElementById('databotCard')
		console.log('element', element)
		setEleStyle(() => {
			return {
				width: element.offsetWidth,
				height: element.offsetHeight
			}
		})
	}, [])
	// title:标题、cellList:结果值、recommend:推荐列名、dateFormat:⽇期列格式、drawType:结果渲染⽅式(线性图、表格等)
	const messageValue = JSON.parse(props.data)
	if (messageValue.cellList.length > 0) {
		if (messageValue.drawType === 'line') {
			return (
				<div id={'databotCard'} className={styles.container}>
					<div className={styles.cardTitle}>{messageValue.title}</div>
					<div className={styles.cardContent}>
						<LineGraph messageValue={messageValue} eleStyle={eleStyle} />
					</div>
					<div className={styles.recommend}>相关推荐</div>
				</div>
			)
		} else {
			return <></>
		}
	} else {
		return <div className={styles.container}>未查询到数据</div>
	}
}
export default GuessAsking
